package com.wcansoft.baseWeb.mybatis_plugin.dao;

import javax.sql.DataSource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


@Component
public class DataSourceBeanUtil implements ApplicationContextAware {
	private static ApplicationContext context;
	private static DataSource dataSource;

	public void setApplicationContext(ApplicationContext contex) throws BeansException {
		DataSourceBeanUtil.context = contex;
	}

	public static ApplicationContext getContext() {
		return context;
	}
	

	public static DataSource getDataSource() {
		if(dataSource!=null)
			return dataSource;
		dataSource = (DataSource)getContext().getBean("dataSource");
		return dataSource;
	}
}
